USE [BMIG_Mensual_POST_CADENA]
GO

 IF EXISTS (SELECT name FROM   sysobjects WHERE  name = N'dbo.WASP_M0014_VALORES_SEGUROS'  AND type = 'P')
    DROP PROCEDURE [dbo].[WASP_M0014_VALORES_SEGUROS]
GO

CREATE PROCEDURE [dbo].[WASP_M0014_VALORES_SEGUROS]
AS


BEGIN
		SELECT a.ppsuc, a.ppcta, a.ppoper,
			   a.ppimp11, a.ppimp12, a.ppimp13, 
			   a.ppimp14, a.ppimp15, a.ppimp16,
			   a.ppimp17, a.ppimp18, a.ppimp19
		
		INTO
		dbo.sc_valseg
		
		FROM fsd611 as a (nolock),
			   fsd601 as b (nolock)
		
		WHERE a.pptipo = '' and a.ppexte = 0  and
			  a.pgcod = b.pgcod and
			  a.ppmod = b.ppmod and
			  a.ppsuc = b.ppsuc and 
			  a.ppmda = b.ppmda and
			  a.ppcta = b.ppcta and 
			  a.ppoper = b.ppoper and
			  a.ppsbop = b.ppsbop and
			  a.pptope = b.pptope and
			  b.d601co = 'S'
		
		GROUP BY a.ppsuc, a.ppcta, a.ppoper, a.ppimp11, a.ppimp12,
				 a.ppimp13, a.ppimp14, a.ppimp15, a.ppimp16,
				 a.ppimp17, a.ppimp18, a.ppimp19

END

